<template>
    <orh-trees  reload  @on-reload="refresh" search :searchOption="typeliat"  :searchOptionSelected="searchOptionSelected" @on-search="searchmt">
		<tree-s slot="trees" @on-treeselect="onTreeselect"></tree-s>

        <orh-sub-table pages :pageDate="pageDate" @on-page-change="Information(type,$event,pageDate.per_page)" slot="content">
            <Table  ref='tableExcel' :data="StudentList" :columns="columns1" highlight-row  :loading="tableload" slot="table"></Table>
        </orh-sub-table>
        <orh-sidebar v-model="show" :title="pageTitle" cover slot="others">
          <!-- <component :is='"StudentBasicInformationLook"' :infoId='infoId' @showParent='showParent=>show=showParent'></component> -->
        </orh-sidebar>
    </orh-trees>
</template>
<script>
  export default {
    name: "studentfilesmodule-studentscomprehensiveassessment",
    components: {
        StudentBasicInformationLook: resolve => {require(['./../Public/StudentBasicInformationLook.vue'], resolve);},
        TreeS: resolve => {require(['./../Public/TreeS.vue'], resolve);},

    },
    data () {
      return {

            searchOptionSelected: 'student_name',
            typeliat: [
				{
					value: 'student_name' ,
					label: '姓名',
				},
				{
					value: 'student_learncode' ,
					label: '学号',
				},
				{
					value: 'identityard_num' ,
					label: '身份证号',
				},
			],

            tableload:true,
            show: false,
            type:'one',
            listUrl:'api/student/v1/studentbase/lists?page=',


            pageDate: {
              total: 0,
              current_page: 1,
              per_page: 10
            },
            pageTitle:null,//右边页面的title

            StudentList:[],//学生变量
            infoId: null,//用于向修改页面传id值

            columns1: [
				{
					title: '学号',
					width: 180,
					key: 'student_learncode'
				},
				{
					title: '姓名',
					width: 120,
					render: (h, params) => {
						let student_name = params.row.student_name!=null?params.row.student_name.zh ? params.row.student_name.zh:params.row.student_name.mn:''
						return h('div', student_name);
					},

				},
				{
					title: '性别',
					width: 80,
					render: (h, params) => {
						let sexname = params.row.sexs?params.row.sexs.dictionary_name.zh ? params.row.sexs.dictionary_name.zh:params.row.sexs.dictionary_name.mn:''
						return h('div', sexname);
					}
				},
				{
					title: '民族',
					width: 120,
					render: (h, params) => {
						let sexname = params.row.ehnic.dictionary_name.zh ? params.row.ehnic.dictionary_name.zh:params.row.ehnic.dictionary_name.mn
						return h('div', sexname);
					}
				},
				{
					title: '出生年月',
					width: 150,
					key: 'birthday'
				},
				{
					title: '身份证号',
					width: 180,
					key: 'identityard_num'
				},
				{
					title: ' ',
				},
				{
					title: '操作',
					key: 'operation',
					fixed: 'right',
					width: 80,
					align: 'center',
					render: (h, params) => {
						return h('div', [
							h('Button', {
								directives: [
									{
										name: "button",
										value: "look"
									}
								],
								props: {
									type: 'success',
									size: 'small'
								},
								style: {
									marginRight: '5px',
								},
								on: {
									click: () => {
									this.look(params.row.student_base_id)
									}
								}
							}, '查看'),
						]);
					}
				}
            ],
        }
    },
    methods: {

        /************************************************************
         *
         * 点击树
         *
         ************************************************************/
		onTreeselect(val){
            this.otherTreeEclassid=null
			if(val.type=='grade'){
					// 点击的是年级
				this.gradeInformation(val.type_id)
			}
			if(val.type=='eclass'){
                this.otherTreeEclassid=val.type_id
					// 点击的是班级
				this.eclassInformation(val.type_id)
			}
		},

        /************************************************************
         *
         * 通过年级获取学生的数据
         *
         ************************************************************/
		gradeInformation(grade_id){
			this.listUrl='api/student/v1/studentlearn/grade_names?grade_id='+grade_id+'&page='
			this.Information('other',1,this.pageDate.per_page)
		},

        /************************************************************
         *
         * 班级获取学生的数据
         *
         ************************************************************/
		eclassInformation(eclass_id){
			this.listUrl='api/student/v1/studentlearn/class_names?eclass_id='+eclass_id+'&page='
			this.Information('other',1,this.pageDate.per_page)
		},

        /************************************************************
         *
         * 获取学生的数据
         *
         ************************************************************/
        Information(type,index=this.pageDate.current_page,per=this.pageDate.per_page){

            this.type=type
            this.tableload=true
            this.StudentList=[]
            this.$http.get(this.listUrl+index+'&per_page='+per).then(val=>{
				let str=val.data.data
                if(type=='other'){
					this.StudentList = str.map((item)=>{
						return item.studentbase ? item.studentbase : null
                    })

                }else{
                    this.StudentList=str
                }
				this.pageDate.total=val.data.total
				this.pageDate.per_page=parseInt(val.data.per_page)
				this.pageDate.current_page=val.data.current_page
                this.tableload=false//加载完数据动画结束               
            }).catch(err=>{
				console.log(err);
				if(err.code && err.code==422) {
					this.$Message.error(err.message);
				}
				this.tableload=false//加载完数据动画结束
            })
        },


        /************************************************************
         *
         * 点击查看
         *
         ************************************************************/
		look (index) {
			this.show=true
			this.infoId = index
            this.pageTitle='查看'
		},

        /************************************************************
         *
         * 刷新数据（当前分页）
         *
         ************************************************************/
        refresh(){
            this.Information(this.type)
        },

        /************************************************************
         *
         * 搜索操作
         *
         ************************************************************/
		searchmt(str,val) {
			this.listUrl='api/student/v1/studentbase/lists?searchtype='+val+'&searchvalue='+str+'&page=',
			this.Information(this.type)
		},

    },
    mounted(){
        // this.Information('one')

    }
  }
</script>
